Skip to content

build: make an unused using a build error (IDE0005) - #1199

Merged
mforce merged 5 commits into
mainfrom
chore/correct-unused-usings
Oct 10, 2026
Merged

mforce merged 5 commits into
mainfrom
chore/correct-unused-usings

Conversation

@mforce

@mforce mforce commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Closes #1187

AGENTS.md said an unused using breaks the build. It did not: on #858 a planted unused using passed both dotnet build and dotnet format, so reviewers have been checking by hand. This PR makes the rule true.

What changes.

  • Directory.Build.props sets GenerateDocumentationFile for every project, with CS1591 (missing XML comment) off. IDE0005 reports during a build only when the compiler produces documentation (dotnet/roslyn#41640).
  • .editorconfig sets IDE0005 to warning, which TreatWarningsAsErrors turns into an error.
  • Cluckwork.Api.csproj drops its own GenerateDocumentationFile=false. That line came from the first scaffold (Scaffold .NET solution #1), and its comment ("Expose Program for WebApplicationFactory") describes something else. Without this change, Api would be the one project the gate skips. With documentation on, the OpenAPI document picks up XML comments, but MapOpenApi is mapped only in Development.
  • The EF migrations tree is exempt from IDE0005. dotnet ef migrations add writes using System;, which ImplicitUsings makes unused, and InitialCreate is frozen (feat(eggs): make cracked and dirty eggs sellable stock via condition grades (#396) #407).

Commits.

  1. bce9273c removes the 208 unused using directives the gate reports, across 181 files, using dotnet format style --diagnostics IDE0005. That is 176 diagnostics, since one diagnostic can cover adjacent lines; the commit message says "176 unused using directives", which counts diagnostics. By project: Application 146, IntegrationTests 152, Infrastructure 36, Domain 12 and Application.Tests 6 diagnostic lines (the build log prints each one twice). It also fixes the five XML doc warnings documentation generation surfaced in Domain. Three crefs had gone stale: two after DiscountReasonCode moved to Contracts, and one pointing into Application, which Domain cannot reference. Two param tags were missing on CeilingBreach. Usings only change what names resolve; the solution builds and the tests below pass.
  2. 54c1ba74 turns on the gate.
  3. 59db4585 updates the docs, and review round 1 narrowed the table in a later commit. src/AGENTS.md and .editorconfig now state what is enforced, and the build: enforce file-scoped namespaces and using placement at build time #985 paragraph counts three gated rules. AGENTS.md gains the Enforced rules table (rule, enforcer, where it runs) for this program's checks: test: cap tracked source files at 500 lines #1153, chore(web): add ESLint with react-hooks rules and bulk suppressions #1155, chore: block forbidden agent git commands with a PreToolUse hook #1158/chore: add git hooks that refuse commits on main and unsafe pushes #1172/chore: run the agent git guard in Pi and Hermes #1175, test(arch): ratchet test types that parse C# without binding symbols #1189, chore(web): add useLatestLoad and lint raw async effects #1190, test(web): require an in-app glossary entry or a reasoned exclusion for every GLOSSARY.md term #1193, ci: flag user-facing strings and glossary changes that ship without their docs #1194 and this PR.

Merge order. The #1189 and #1193 rows name tests that land with those PRs, which are still open.

Tests run locally: dotnet build Cluckwork.slnx --no-incremental (0 warnings, 0 errors), Domain.Tests (496 passed), Application.Tests (766 passed), and the two IntegrationTests ImagePin guards.

Proof.

  • A real past case. feat: let an Owner turn connected apps off for the farm #1147 (077f27e7, 2026-10-09) added using Cluckwork.Infrastructure.Persistence; and using Microsoft.AspNetCore.Mvc.Testing; to OAuthFailClosedTests.ConnectedAppsSwitch.cs, and neither was ever used. This PR removes them. Putting both back on the branch head fails dotnet build Cluckwork.slnx:
    tests/Cluckwork.Api.IntegrationTests/OAuthFailClosedTests.ConnectedAppsSwitch.cs(8,1): error IDE0005: Using directive is unnecessary.
  • Api, the project the gate used to skip. A planted using System.Text.RegularExpressions; in IdempotencyMiddleware.cs fails the build:
    src/Cluckwork.Api/Middleware/IdempotencyMiddleware.cs(1,1): error IDE0005: Using directive is unnecessary.
  • After both reverts, the build reports 0 warnings and 0 errors.

Build time. No measurable change. Four alternating dotnet build Cluckwork.slnx --no-incremental runs on this shared host (load 12–16) took 27.6 s and 27.6 s on the branch, against 29.3 s and 26.3 s on main at 734a8343.
Output changes.

  • dotnet publish now ships four XML documentation files with the image: Cluckwork.Api.xml, Cluckwork.Application.xml, Cluckwork.Domain.xml and Cluckwork.Infrastructure.xml, about 64 KB in total. The SDK sets PublishDocumentationFile and PublishReferencesDocumentationFiles by default.
  • AddOpenApi() reads these XML comments into the OpenAPI document, which .NET 10 does by default. The document is served only in Development (MapOpenApi() in Program.cs), so production responses do not change.

Removes the 176 unused using directives that IDE0005 reports once the
compiler produces documentation, and fixes the five XML doc warnings it
also surfaces in Domain: three crefs left stale when DiscountReasonCode
moved to Contracts or that point into Application, and two missing param
tags on CeilingBreach.
IDE0005 reports during a build only when the compiler produces
documentation (dotnet/roslyn#41640), so a planted unused using passed the
build and dotnet format on #858. GenerateDocumentationFile is now on for
every project, with CS1591 off, and IDE0005 is a warning, which
TreatWarningsAsErrors turns into an error. Migrations are exempt: the
scaffold writes using System; and InitialCreate is frozen (#407).

Closes #1187
@mforce mforce added this to the Platform hardening milestone Oct 10, 2026
@mforce

mforce commented Oct 10, 2026

Copy link
Copy Markdown
Owner Author

Review round 1 (Codex, read-only) at 59db4585.

Build gate: works. A temporary unused using fails with IDE0005 in all ten projects, including Api, AppHost and the Analyzers project. The migrations exemption covers only Infrastructure/Persistence/Migrations; the same probe fails in Persistence/ and in Infrastructure/Migrations/. None of the 208 removed usings changes binding: 169 duplicate global or SDK imports, and the #if blocks in changed files sit inside raw-string fixtures. Scoped Release builds show no measurable cost from GenerateDocumentationFile.

Finding 1 (doc): the Enforced rules table promises more than the checks enforce. Rows to narrow (AGENTS.md:117-121):

Smallest fix: state each check's real trigger and exemptions, and leave the checks as they are.

Note for the body, not a defect: publish output now includes four XML doc files (about 64 KB), and the Development-only OpenAPI document picks up the XML comments.

VERDICT: 0 product defects, 1 doc finding.

@mforce

mforce commented Oct 10, 2026

Copy link
Copy Markdown
Owner Author

Reply to review round 1. The head is now b7ed22c4, with origin/main (#1188) merged in.

Finding 1 (the table promised more than the checks enforce). Fixed in b7ed22c4; no check changed. The column is now "Check fails on", and each row states the real trigger and exemptions from your audit:

The intro says a row can be narrower than the prose rule it backs, and that frozen hits stop new cases only.

Output notes. The PR body now names the four published XML files (about 64 KB, from the SDK's publish defaults). It also notes that AddOpenApi() folds the comments into the OpenAPI document, which is served only in Development.

Checks on b7ed22c4: the AGENTS.md documentation guards passed (20 of 20).

@mforce
mforce merged commit fd3f196 into main Oct 10, 2026
21 of 22 checks passed
@mforce
mforce deleted the chore/correct-unused-usings branch October 10, 2026 23:35
mforce added a commit that referenced this pull request Oct 10, 2026
Folds #806's OAuth audience and MCP tool-gate rules into src/AGENTS.md, and
ports the rules #1188, #1190, #1193 and #1199 added to the instruction files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make unused C# usings a build error

1 participant